/**
 * 
 */
package com.ingesup.services;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.ingesup.entities.Contact;
import com.ingesup.entities.ListeDeDiffusion;

/**
 * @author FDEJEAN
 *
 */
public class ListeDeDiffusionServiceTest {

	private static ListeDeDiffusionService service;
	private static ListeDeDiffusion liste;
	
	@Before
	public void beforeTest() {
		service = new ListeDeDiffusionServiceImpl();		
	}
	
	/**
	 * Test method for {@link com.ingesup.services.ListeDeDiffusionServiceImpl#createListeDeDiffusion(com.ingesup.entities.ListeDeDiffusion)}.
	 */
	@Test
	public void testCreateListeDeDiffusion() {
		ListeDeDiffusion temp = new ListeDeDiffusion();
		List<Contact> liste = new ArrayList<Contact>();
		Contact contact = new Contact();
		contact.setNom("DEJEAN");
		contact.setAdresseMail("florian.dejean@gmail.com");
		liste.add(contact);
		temp.setNom("maListe");
		temp.setListeDeContacts(liste);
		
		ListeDeDiffusion temp2 = service.createListeDeDiffusion(temp);
		assertNotNull(temp2);
		assertTrue(temp2.getId() > 0);
	}

	/**
	 * Test method for {@link com.ingesup.services.ListeDeDiffusionServiceImpl#getListListeDeDiffusion()}.
	 */
	@Test
	public void testGetListListeDeDiffusion() {
		List<ListeDeDiffusion> tempList = new ArrayList<ListeDeDiffusion>();
		tempList = service.getListListeDeDiffusion();
		assertEquals(1, tempList.size());
		liste = tempList.get(0);
	}

	/**
	 * Test method for {@link com.ingesup.services.ListeDeDiffusionServiceImpl#getListeDeDiffusion(long)}.
	 */
	@Test
	public void testGetListeDeDiffusion() {
		ListeDeDiffusion temp = service.getListeDeDiffusion(liste.getId());
		assertNotNull(temp);
		assertNotNull(temp.getNom());
		assertNotNull(temp.getListeDeContacts());
	}
	
	/**
	 * Test method for {@link com.ingesup.services.ListeDeDiffusionServiceImpl#updateListeDeDiffusion(com.ingesup.entities.ListeDeDiffusion)}.
	 */
	@Test
	public void testUpdateListeDeDiffusion() {
		ListeDeDiffusion temp = service.getListeDeDiffusion(liste.getId());
		temp.setNom("Nounouille");
		service.updateListeDeDiffusion(temp);
		
		temp = service.getListeDeDiffusion(liste.getId());
		assertEquals("Nounouille", temp.getNom());
	}

	/**
	 * Test method for {@link com.ingesup.services.ListeDeDiffusionServiceImpl#deleteListeDeDiffusion(com.ingesup.entities.ListeDeDiffusion)}.
	 */
	@Test
	public void testDeleteListeDeDiffusion() {
		service.deleteListeDeDiffusion(liste);
		assertEquals(0, service.getListListeDeDiffusion().size());
	}
}
